@extends('master')

@section('官方活动', 'Page Title')

@section('sidebar')
	@parent
@endsection

@section('content')
	<div class="panel panel-info">
		<div class="panel-heading">
			<div class="panel-title">官方活动</div>
		</div>
		<div class="panel-body" >
			<form method="POST" action="{{ isset($id) ? '/admin/activitys/update/' . $id : '/admin/activitys/store'}}" class="form-horizontal" enctype="multipart/form-data" role="form">
				{!! csrf_field() !!}
				<fieldset>
					<input type="hidden" name="id" value="{{ $id or ''}}" />
					<div class="form-group">
						<label class="col-md-3 control-label" for="title">标题</label>
						<div class="col-md-9">
							<input id="title" name="title" type="text" placeholder="标题" class="form-control input-md" value="{{ $title or '' }}">
						
						</div>
					</div>
					<div class="form-group">
						<label class="col-md-3 control-label" for="img">图片</label>
						<div class="col-md-9">
							<input id="img" name="img" type="file" placeholder="图片" class="input-md"">
							@if(isset($img))
								<img src="/{{ $img }}" height="100px;" style="margin-top: 10px;">
							@endif
						</div>
					</div>
					<div class="form-group">
						<label class="col-md-3 control-label" for="desc">描述</label>
						<div class="col-md-9">
							<input id="desc" name="desc" type="text" placeholder="描述" class="form-control input-md" value="{{ $desc or '' }}">
						
						</div>
					</div>
					<div class="form-group">
						<label class="col-md-3 control-label" for="desc">活动时间</label>
						<div class="col-md-9">
							<input id="date_time" name="date_time" type="text" placeholder="活动时间" class="form-control input-md" value="{{ $date_time or '' }}">
						</div>
					</div>
					
					<div class="form-group">
						<label class="col-md-3 control-label" for="submit"></label>
						<div class="col-md-9">
							<button id="submit" name="submit" class="btn btn-primary">提交</button>
								<span id="errors" style="margin-left: 10%; color: red;">
								@if(count($errors) > 0)
									{{ $errors->all()[0] }}
								@endif
								</span>
						</div>
					</div>
				
				</fieldset>
			
			</form>
		</div>
	</div>
	<script src="https://cdn.bootcss.com/bootstrap-datepicker/1.7.0-RC2/js/bootstrap-datepicker.js"></script>
	<script>
	$(function(){
		$('#date_time').datepicker({
            language: "zh-CN",
            autoclose: true,//选中之后自动隐藏日期选择框
            clearBtn: true,//清除按钮
            //todayBtn: true,//今日按钮
            format: "yyyy-mm-dd"//日期格式
        });
	});
		$('#submit').click(function(){

			var title = $('#title').val();
			var img = $('#img').val();
			var desc = $('#desc').val();
			var date_time = $('#date_time').val();

			<?php if (isset($id)) {?>
				if (!title || !desc || !date_time) {

					$('#errors').text('请将字段填写完整!');
					return false;
				}else{

					$('#errors').text('');
				}
			<?php }else{?>

				if (!title || !img || !desc || !date_time) {

					$('#errors').text('请将字段填写完整!');
					return false;
				}else{

					$('#errors').text('');
				}
			<?php }?>

			
		});

	</script>
@endsection